{% extends 'base.html' %}

{% block content %}

    <!-- Plugins css-->
    <link href="/static/assets/plugins/bootstrap-tagsinput/dist/bootstrap-tagsinput.css" rel="stylesheet" />
    <link href="/static/assets/plugins/switchery/dist/switchery.min.css" rel="stylesheet" />
    <link href="/static/assets/plugins/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css" rel="stylesheet">
    <link href="/static/assets/plugins/select2/select2.css" rel="stylesheet" type="text/css" />
    <link href="/static/assets/plugins/multiselect/css/multi-select.css"  rel="stylesheet" type="text/css" />
    <link href="/static/assets/plugins/bootstrap-select/dist/css/bootstrap-select.min.css" rel="stylesheet" />
    <link href="/static/assets/plugins/summernote/dist/summernote.css" rel="stylesheet" />


    <div class="container">
                <!-- Page-Title -->
                <div class="row">
                    <div class="col-sm-12">
                        <h4 class="page-title">服务器修改</h4>
                        <ol class="breadcrumb">
                            <li>
                                <a href="#">资产管理</a>
                            </li>
                            <li>
                                <a href="{% url 'ServerList' 1 %}">服务器列表</a>
                            </li>
                            <li class="active">
                                服务器修改
                            </li>
                        </ol>
                    </div>
                </div>

                <form class="form-horizontal" role="form">
                    {% csrf_token  %}

                    <div class="row">
                        <div class="col-sm-8">
                            <div class="card-box">
                                <h4 class="m-t-0 header-title"><b>基本信息:</b></h4>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">选择关联资产:</label>
                                            <div class="col-md-9">
                                                <select class="selectpicker show-tick" data-style="btn-white" name="Assets">
                                                    {% for asset in AssetsData%}
                                                        {% if ServerData.Assets.id == asset.id %}
                                                            <option value="{{asset.id}}" selected>{{asset.host_name}}</option>
                                                        {% else %}
                                                            <option value="{{asset.id}}">{{asset.host_name}}</option>
                                                        {% endif %}
                                                    {%endfor%}
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">服务器SN:</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" value="{{ServerData.sn}}" name="sn">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">主机名:</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" value="{{ServerData.hostname}}" name="hostname">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">厂商:</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" value="{{ServerData.Firm}}" name="firm">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">saltstack ID:</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" value="{{ServerData.saltid}}" name="saltid">
                                            </div>
                                        </div>
                                    </div>
                                     <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">内存:</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" value="{{ServerData.mem}}" name="mem">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                                <label class="col-md-3 control-label">Swap:</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" value="{{ServerData.swap}}" name="swap">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">系统平台:</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" value="{{ServerData.platform}}" name="platform">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">系统:</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" value="{{ServerData.system}}" name="system">
                                            </div>
                                        </div>
                                         <div class="form-group">
                                            <label class="col-md-3 control-label">系统版本:</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" value="{{ServerData.version}}" name="version">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-sm-8">
                            <div class="card-box">
                                <h4 class="m-t-0 header-title"><b>硬件信息：</b></h4>
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">CPU关联:</label>
                                            <div class="col-md-9">
                                                <select class="selectpicker show-tick" data-style="btn-white" name="CPU">
                                                    {% for cpu in CpuData %}
                                                        {% if ServerData.cpu.id == cpu.id %}
                                                            <option value="{{cpu.id}}" selected>{{cpu.model}}</option>
                                                        {%else%}
                                                            <option value="{{cpu.id}}">{{cpu.model}}</option>
                                                        {% endif %}
                                                    {%endfor%}
                                                </select>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">CPU个数:</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" value="{{ServerData.cpu_count}}" name="cpu_count">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">CPU核数:</label>
                                            <div class="col-sm-9">
                                                <input type="text" class="form-control" value="{{ServerData.cpu_core_count}}" name="cpu_core_count">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">网卡列表:</label>
                                            <div class="col-sm-9">
                                                <select multiple="multiple" class="multi-select" id="my_multi_select1" name="nic" data-plugin="multiselect">
                                                    {% for i in NicData %}
                                                        {% if i in   ServerData.nic.all %}
                                                            <option value="{{i.id}}" selected>{{i.ip}}</option>
                                                        {% else %}
                                                            <option value="{{i.id}}" >{{i.ip}}</option>
                                                        {%endif%}
                                                    {%endfor%}
                                                </select>
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">硬盘列表:</label>
                                            <div class="col-md-9">
                                                <select multiple="multiple" class="multi-select" id="my_multi_select2" name="disk" data-plugin="multiselect">
                                                    {% for i in DiskData %}
                                                        {% if i in   ServerData.disk.all %}
                                                            <option value="{{i.id}}" selected>{{i.parent_sn}}</option>
                                                        {% else %}
                                                            <option value="{{i.id}}" >{{i.parent_sn}}</option>
                                                        {%endif%}
                                                    {%endfor%}
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">安装软件列表:</label>
                                            <div class="col-sm-9">
                                                <select multiple="multiple" class="multi-select" id="my_multi_select3" name="software" data-plugin="multiselect">
                                                    {% for i in SoftwareData %}
                                                        {% if i in   ServerData.software.all %}
                                                            <option value="{{i.id}}" selected>{{i.name}}</option>
                                                        {% else %}
                                                            <option value="{{i.id}}" >{{i.name}}</option>
                                                        {%endif%}
                                                    {%endfor%}
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-3 control-label">RAID级别:</label>
                                            <div class="col-md-9">
                                                <input type="text" class="form-control" value="{{ServerData.raid}}" name="raid">
                                            </div>
                                        </div>

                                        <div class="form-group">
                                            <label class="col-md-3 control-label">添加方式</label>
                                            <div class="col-md-9">
                                                <select class="selectpicker show-tick" data-style="btn-white" name="addtype">
                                                    {% for i in ServerData.add_type_choice %}
                                                        {% if ServerData.addtype == i.0 %}
                                                            <option value="{{i.0}}" selected>{{i.1}}</option>
                                                        {%else%}
                                                            <option value="{{i.0}}">{{i.1}}</option>
                                                        {%endif%}
                                                    {%endfor%}
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <!-- 提交按钮 -->
                    <div class="row">
                        <div class="col-sm-8">
                            <div class="form-group text-right">
                                <button type="submit" class="btn btn-primary">
                                    提交
                                </button>
                            </div>
                        </div>
                    </div>

                </form>

            </div> <!-- container -->


<script type="text/javascript" src="/static/assets/plugins/multiselect/js/jquery.multi-select.js"></script>
<script src="/static/assets/plugins/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script src="/static/assets/plugins/select2/select2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="/static/assets/plugins/multiselect/js/jquery.multi-select.js"></script>
<script src="/static/assets/plugins/bootstrap-select/dist/js/bootstrap-select.min.js" type="text/javascript"></script>

<script>
    jQuery(document).ready(function() {
        // Select2
        $(".select2").select2();
        $(".select2-limiting").select2({
            maximumSelectionLength: 2
        });
        $('.selectpicker').selectpicker();
        $('button[type=submit]').click(function(e) {
            e.preventDefault();
            $.ajax({
                        type: 'POST',
                        url: '{% url "ChangeServer" ServerData.id %}',
                        data: $('.form-horizontal').serialize(),
                        success: function(data) {
                            $.Notification.autoHideNotify('success','top right','系统通知', '服务器信息修改成功');
                            setTimeout(function() {
                                   location.href = '{% url 'ServerList'  1 %}';
                              },2500);
                        },
                        error: function() {},

            });
        });

    })

</script>

{%endblock%}
